package com.db.mylogging;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class AsyncAppender implements Appender {

	private final Appender appender;
	private final ExecutorService executor;

	public AsyncAppender(Appender appender) {
		this.appender = appender;
		executor = Executors.newSingleThreadExecutor();
	}

	@Override
	public void append(final String message) {
		executor.execute(new Runnable() {
			@Override public void run() {
				appender.append(message);
			}
		});

	}

	@Override
	public void close() {
		executor.shutdown();
		appender.close();
	}

}
